<?php
function load_model ($modeldir, $type = 'require'){
	if(!file_exists(APP_DIR."/models/".$modeldir."Model.php")){
		php_alert($modeldir."文件不存在");
		return false;
	}
	if($type == 'include'){
		include_once(APP_DIR."/models/".$modeldir."Model.php");
	}else{
		require_once(APP_DIR."/models/".$modeldir."Model.php");
	}
	
	return true;
}

function load_ctl ($ctldir){
	if(preg_match("/^admin_.+$/i",$ctldir)):
		$ctldir = str_replace("admin_","",$ctldir);
		if(!file_exists(APP_DIR."/modules/admin/controllers/".$ctldir."Controller.php")){
			php_alert($ctldir."文件不存在");
			return false;
		}
		require_once(APP_DIR."/modules/admin/controllers/".$ctldir."Controller.php");
		return true;
	endif;
	if(!file_exists(APP_DIR."/modules/default/controllers/".$ctldir."Controller.php")){
		php_alert($ctldir."文件不存在");
		return false;
	}
	require_once(APP_DIR."/modules/default/controllers/".$ctldir."Controller.php");
	return true;
}

function load_inc($inc){
	if(!file_exists(APP_DIR."/include/".$inc.".php")){
		php_alert($inc."文件不存在");
		return false;
	}
	require_once(APP_DIR."/include/".$inc.".php");
	return true;
}

function log_file($a){
	$file = '/tmp/log/zend-php-blog.log';
	if(is_array($a)){
		ob_start();
		print_r($a);
		echo "\n";
		$b = ob_get_contents();
		ob_clean();
		error_log($b,3,$file);
	}else{
		$c =error_log($a."\n",3,$file);
	}
	
}

?>